// 定义了校验函数类型
import { RuleObject } from 'antd/lib/form';
type CustomValidator = (rule: RuleObject, value: any, callback: (error?: string | undefined) => void) => void | Promise<any>

// 图片验证码格式校验
export const checkImgCode: CustomValidator = (_rule, value) => {
  const reg = /^\d{4}$/;
  if (value) {
    if (typeof value === 'string') {
      if (reg.test(value)) {
        return Promise.resolve();
      } else {
        return Promise.reject(new Error('请输入正确的图片验证码'))
      }
    }
  } else {
    return Promise.reject(new Error('请输入图片验证码'));
  }
}


// 手机号格式校验
export const checkMobilePhone: CustomValidator = (_rule, value) => {
  const myreg=/^1[3-9]\d{9}$/;
  if (!myreg.test(value)) {
    return Promise.reject(new Error('请输入正确的手机号'));
  } else {
    return Promise.resolve();
  }
}